import { ConfigEnv, UserConfig } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'node:path';
import AutoImport from 'unplugin-auto-import/vite';

// https://vite.dev/config/
export default (configEnv: ConfigEnv):UserConfig => {
  const isProduction = configEnv.mode === 'production';

  return {
    base: '/', // 设置基础路基
    plugins: [
      react(), // 启用react支持
      AutoImport({
        imports: [
          'react',
          {
            'antd': [
              'Alert',
              'Button',
              'ConfigProvider',
              'Form',
              'Input',
            ],
          },
          {
            '@ricons/utils': ['Icon'],
          },
          {
            'recoil': [
              'useRecoilValue'
            ]
          }
        ],
        dts: 'src/types/auto-imports.d.ts',
      }),
    ],
    resolve: {
      alias: {
        '@': path.resolve(__dirname, './src')
      }
    },
    css: {
      preprocessorOptions: {
        less: {
          modifyVars: {
            'input-hover-border-color': '#62ccc6',
            'input-active-border-color': '#62ccc6',
          },
          javascriptEnabled: true,
        }
      }
    },
    server: {
      host: true,
      open: false,
    },
    build: {
      outDir: 'dist',
      sourcemap: !isProduction,
      rollupOptions: {
        output: {
          manualChunks: {
            react: ['react', 'react-dom']
          }
        }
      }
    }
  };
};
